// Copyright 2009 Ivan Wong. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// This package provides the FastCGI application interface
// implementation for GO.
// Heavily inspired by fcgigo: git://github.com/jldailey/fcgigo.git
// Many ideas are directly borrowed from it
package main

import (
        "fmt"
        "fastcgi"
        "os"
)

type Application struct {
}

func (a *Application) Handle(r *fastcgi.Request) bool {
	fmt.Fprintf(r.Stdout, "Content-type: text/html\r\n\r\n")
	fmt.Fprintf(r.Stdout, "hello world!<br>\n")
	fmt.Fprintf(r.Stdout, "stdin: (")
	for {
		s, e := r.Stdin.ReadString('\n')
		if e != nil {
			break
		}
		fmt.Fprintf(r.Stdout, "%s", s)
	}
	fmt.Fprintf(r.Stdout, ")")
	return true
}

func main() {
	a := new(Application)
        err := fastcgi.RunStandalone(":12345", a)
        if err != nil {
                fmt.Fprintf(os.Stderr, "err in main: %s", err.String())
                os.Exit(1)
        }
}

